import oolongSpin from './oolong-spin.js';

let spinInstance;

function getSpinInstance(render = undefined) {
  spinInstance = spinInstance || oolongSpin.newInstance({
    render: render
  });
  return spinInstance;
}

function loading(options) {
  const render = ('render' in options) ? options.render : undefined;
  let instance = getSpinInstance(render);
  instance.show(options);
}

oolongSpin.show = function (props = {}) {
  return loading(props);
};

oolongSpin.hide = function () {
  if (!spinInstance) return false;
  const instance = getSpinInstance();
  instance.remove(() => {
    spinInstance = null;
  });
};

export default oolongSpin;
